#!/bin/bash

TOP = top_tb
#适用于第一次，自动加载代码文件，编译，打开波形，但是最好结合实际情况，尽量一步一步操作
all:
	make load_file
	make compile
	make wave

#更新代码文件,只有新增文件时需要用到(注意：把sv类型的testbench放在前面优先编译，以设置全局的timescale)
load_file:
	# find ../TB  -name "*.sv" -o -name "*.v" >  filelist.f
	# find ../RTL -name "*.sv" -o -name "*.v" >> filelist.f
	cat ../TB/filelist.f ../RTL/filelist.f > filelist.f

load_postdc_file:
	# find ../TB  -name "*.sv" -o -name "*.v" >  filelist.f
	# find ../RTL -name "*.sv" -o -name "*.v" >> filelist.f
	echo "/SM01/home/bs2020/bs202030050035/TSMC_N28/TSMCHOME/digital/Front_End/verilog/tcbn28hpcplusbwp12t40p140_170a/tcbn28hpcplusbwp12t40p140.v" > filelist.f
	cat ../TB/filelist.f >> filelist.f
	find ../Synthesize/results -name "*.v" >> filelist.f
	
#更新编译，每次更新代码都需要，-q用来减少无用打印信息，-R立即运行仿真，但不建议，建议使用交互式仿真
compile:
	vcs -fgp -full64 \
	-f filelist.f \
	-sverilog +v2k +neg_tchk \
	-debug_access+all \
	+lint=all,noLCA_FEATURES_ENABLED,noIWU,noOUDPE,noNS \
	-timescale=1ns/1ps \
	-kdb -lca -q \
	-l ./output.log -o $(TOP)
# vcs -full64 -f filelist.f -sverilog +v2k -debug_access+all -q -timescale=1ns/10ps -lca -kdb -R -l ./output.log -o $(TOP)

#打开波形，只需要打开一次，后面用tcl脚本reload;或者compile之后restart即可
wave:
	./$(TOP) -gui=verdi &
# ./$(TOP) -fgp=num_threads:15,sync:busywait,auto_affinity -gui=verdi &
# verdi -sverilog -ssf top.fsdb -f filelist.f -ssr Verdi.ses &

#清除工程,grep为保留文件
.PHONY:clean
clean:
	ls -a | \
	grep -v . | \
	grep -v .. | \
	grep -v Makefile | \
	grep -v filelist.f | \
	grep -v novas.rc | \
	xargs rm -rf
